package com.example.demo.common;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class AppConfig implements WebMvcConfigurer {

    //不拦截的url集合
    List<String> excludes=new ArrayList<String>(){{
        add("/**/*.html");
        add("/css/**");
        add("/img/**");
        add("/js/**");
        add("/editor.md/**");
        add("/user/login");
        add("/user/reg");
        add("/art/detail");
        add("/art/list");
        add("/art/totalpage");
        add("/user/myinfobyuid");

    }};

    @Autowired
    private LoginInterceptor loginInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration registration=
                registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(excludes);
    }
}
